﻿/// <reference path="math-utils.js" />
/// <reference group="Dedicated Worker" />
var isPrime = function (number) {
    for (var i = 2; i < number; i++) {
        if (number % i == 0) {
            return false;
        }
    }
    return true;
}

var calculateFirstNPrimes = function (firstNPrimes) {
    var primesList = [];
    var counter = 0;

    while (primesList.length != firstNPrimes) {
        if (isPrime(counter)) {
            primesList.push(counter);
        }
        counter++;
    }

    return primesList;
}

onmessage = function (event) {
    var firstNPrimes = event.data.firstNPrimes;

    var primes = calculateFirstNPrimes(firstNPrimes);

    postMessage(primes);
}
